let originProto = Array.prototype;

let methodProto = Object.create(originProto);

let methodList = [
  "push",
  "pop",
  "shift",
  "unshift",
  "splice",
  "sort",
  "reverse",
];

methodList.forEach((methodName) => {
  def(
    methodProto,
    methodName,
    function () {
      let ob = this.__ob__;
      let inserted = [];
      switch (methodName) {
        case "push":
          inserted = [...arguments];
          break;
        case "unshift":
          inserted = [...arguments];
          break;
        case "splice":
          inserted = [...arguments].slice(2);
          break;
        default:
          break;
      }
      if (inserted) {
        ob.observeArray(inserted);
      }
      ob.dep.notify();
      console.log("tongguo重写修改了数据");
      const result = originProto[methodName].apply(this, arguments);
      return result;
    },
    true
  );
});
